from api.models import OperationLog
from django.utils import timezone

def log_operation(user, operation, ip_address):
    """
    记录操作日志
    :param user: 用户对象
    :param operation: 操作内容
    :param ip_address: IP地址
    :return: OperationLog对象
    """
    return OperationLog.objects.create(
        user=user,
        operation=operation,
        ip_address=ip_address,
        created_at=timezone.now()
    ) 